package com.java.mascotaspoliticas;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Copyright 2011 Lorensius W. L. T

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
    
  */  
public class Mascota extends Activity {
	//action id
  	private static final int ID_HAMBURGUESA  = 1;
  	private static final int ID_REFRE   = 2;
  	private static final int ID_BIRRA  = 3;
  	private static final int ID_AREPA  = 4;
  	private Handler mHandler;
  	private TextView dinero;
  	private TextView aprobacion;
  	private TextView vida;
  	private ImageView feliz;
  	private ProgressBar hambre;
  	private ProgressBar bano;
	private int v;
	private int a;
	private int f;
	private int d;
	private int h;
	private int b;
	private int cantHam=0;
	private int cantBirra=0;
	private String pers;
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
  		setContentView(R.layout.menu);
  		this.cargarBarra();
  		this.dinero=(TextView) findViewById(R.id.textDinero);
  		this.vida= (TextView) findViewById(R.id.textVida);
  		this.aprobacion=(TextView) findViewById(R.id.textAprob);
  		this.feliz=(ImageView) findViewById(R.id.feliz);
  		this.hambre=(ProgressBar)findViewById(R.id.barraHambre);
  		this.bano=(ProgressBar)findViewById(R.id.barraBano);
  		v = Integer.parseInt((String)vida.getText());
  		a=Integer.parseInt((String)aprobacion.getText());
  		f=100;
  		d=Integer.parseInt((String)dinero.getText());
  		h=hambre.getProgress();
  		b=bano.getProgress();
  		
        mHandler = new Handler();
        mHandler.post(mUpdateVida);
        mHandler.post(mUpdateAprobacion);
        mHandler.post(mUpdateFeliz);
        mHandler.post(mUpdateHambre);
        mHandler.post(mUpdateBano);
  		//Cambiamos la barra que se mostrara en el menu
        
        TextView txtV = (TextView) findViewById(R.id.textVida);  
        TextView txtA = (TextView) findViewById(R.id.textAprob);
        TextView txtD = (TextView) findViewById(R.id.textDinero);
        Typeface font = Typeface.createFromAsset(getAssets(), "sketchblock.ttf");  
        txtV.setTypeface(font);
        txtA.setTypeface(font);
        txtD.setTypeface(font);

  		ActionItem hamburguesaItem 	= new ActionItem(ID_HAMBURGUESA, "Hamburguesa", getResources().getDrawable(R.drawable.hamburg));
  		ActionItem pepsiItem 	= new ActionItem(ID_REFRE, "Pepsi", getResources().getDrawable(R.drawable.refresco));
         ActionItem birraItem 	= new ActionItem(ID_BIRRA, "Birra", getResources().getDrawable(R.drawable.birra));
       ActionItem arepaItem = new ActionItem(ID_AREPA, "Arepa", getResources().getDrawable(R.drawable.miniarepa));
          //use setSticky(true) to disable QuickAction dialog being dismissed after an item is clicked
  		hamburguesaItem.setSticky(true);
        pepsiItem.setSticky(true);
  		birraItem.setSticky(true);
  		//create QuickAction. Use QuickAction.VERTICAL or QuickAction.HORIZONTAL param to define layout 
          //orientation
  		final QuickAction3D invComidas = new QuickAction3D(this, QuickAction3D.HORIZONTAL);
  		final QuickAction3D invBebidas = new QuickAction3D(this, QuickAction3D.HORIZONTAL);
  		//add action items into QuickAction
          invComidas.addActionItem(hamburguesaItem);
          invBebidas.addActionItem(pepsiItem);
          invBebidas.addActionItem(birraItem);
          invComidas.addActionItem(arepaItem);
          
          //Set listener for action item clicked
          invComidas.setOnActionItemClickListener(new QuickAction3D.OnActionItemClickListener() {			
    			@Override
    			public void onItemClick(QuickAction3D source, int pos, int actionId) {				
    				ActionItem actionItem = invComidas.getActionItem(pos);
    				//here we can filter which action item was clicked with pos or actionId parameter
    				if (actionId == ID_HAMBURGUESA) {
    					
    					if (cantHam > 0){
  	  					//Toast.makeText(getApplicationContext(), "Gordeando en calle del hambre no perrito", Toast.LENGTH_SHORT).show();
  	  					//vida
  	  					v=v+10;
  	  					if(v>100){
  	  						v=100;
  	  					}
  	  					vida.setText(""+v);
  	  					
  	  					//comida
  	  					h=h+15;
  	  					
  	  					if(h>100){
  	  						h=100;
  	  					}
  	  					b=b+12;
  	  					if(b>100){
  	  						b=100;
  	  					}
  	  					hambre.setProgress(h);
  	  					bano.setProgress(b);
    					}else{
    						Toast.makeText(getApplicationContext(), "No tienes de esta comida debes comprar", Toast.LENGTH_SHORT).show();
    					}
    					
    				} else if(actionId == ID_AREPA){
    					
    					//Toast.makeText(getApplicationContext(), "Una arepita pa' pasa la pea", Toast.LENGTH_SHORT).show();
    					//vida
    					v=v+15;
    					if(v>100){
    						v=100;
    					}
    					vida.setText(""+v);
    					
    					//comida
    					h=h+10;
    					
    					if(h>100){
    						h=100;
    					}
    					b=b+8;
    					if(b>100){
    						b=100;
    					}
    					hambre.setProgress(h);
    					bano.setProgress(b);
    				}	else {
    				
    					Toast.makeText(getApplicationContext(), actionItem.getTitle() + " selected", Toast.LENGTH_SHORT).show();
    				}
    			}
    		});
    		
    		
    		invBebidas.setOnActionItemClickListener(new QuickAction3D.OnActionItemClickListener() {			
    			@Override
    			public void onItemClick(QuickAction3D source, int pos, int actionId) {				
    				ActionItem actionItem = invBebidas.getActionItem(pos);
    				//here we can filter which action item was clicked with pos or actionId parameter
    				if (actionId == ID_REFRE) {
    					//Toast.makeText(getApplicationContext(), "Te toco la sin gas pelaste ", Toast.LENGTH_SHORT).show();
    				//comida
    					h=h+3;
    					
    					if(h>100){
    						h=100;
    					}
    					b=b+10;
    					if(b>100){
    						b=100;
    					}
    					hambre.setProgress(h);
    					bano.setProgress(b);

    					
    					hambre.setProgress(h);
    				} else if (actionId == ID_BIRRA) {
    					if(cantBirra>0){
  	  					//Toast.makeText(getApplicationContext(), "Una birra y me voy ..(aja..) ", Toast.LENGTH_SHORT).show();
  	  				//vida
  	  					v=v-5;
  	  					if(v<=0){
  	  						v=0;
  	  						vida.setText(""+v);
  	  						AlertDialog.Builder builder = new AlertDialog.Builder(Mascota.this);
  	  	    	    	   builder.setMessage("Perdiste, tu mascota ha muerto")
  	  	    	    	          .setCancelable(false)
  	  	    	    	          .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
  	  	    	    	              public void onClick(DialogInterface dialog, int id) {
  	  	    	    	                   Mascota.this.finish();
  	  	    	    	              }
  	  	    	    	          });
  	  	    	    	   AlertDialog alert = builder.create();
  	  	    	    	   alert.show();
  	  						
  	  					}
  	  					b=b+15;
  	  					if(b>100){
  	  						b=100;
  	  					}
  	  					vida.setText(""+v);
  	  					bano.setProgress(b);
  	  					
    					}else{
    						Toast.makeText(getApplicationContext(), "No tienes de esta bebida debes comprar", Toast.LENGTH_SHORT).show();
    					}
    				} else {
    					Toast.makeText(getApplicationContext(), actionItem.getTitle() + " selected", Toast.LENGTH_SHORT).show();
    				}
    			}
    		});
  		
  		//set listnener for on dismiss event, this listener will be called only if QuickAction dialog was dismissed
  		//by clicking the area outside the dialog.
  		invComidas.setOnDismissListener(new QuickAction3D.OnDismissListener() {			
  			@Override
  			public void onDismiss() {
  				Toast.makeText(getApplicationContext(), "Dismissed", Toast.LENGTH_SHORT).show();
  			}
  		});
  		
  		//show on btn1
  		Button comer = (Button) this.findViewById(R.id.comer);
  		comer.setOnClickListener(new View.OnClickListener() {
  			@Override
  			public void onClick(View v) {
  				invComidas.show(v);
  				invComidas.setAnimStyle(QuickAction3D.ANIM_REFLECT);
  			}
  		});
       
  		/*Button button1 = (Button) this.findViewById(R.id.button1);
  		button1.setOnClickListener(new OnClickListener() {
  			@Override
  			public void onClick(View v) {
  				quickAction.show(v);
  			}    	 
  		});
  		*/
  		Button beber = (Button) this.findViewById(R.id.beber);
  		beber.setOnClickListener(new OnClickListener() {
  			@Override
  			public void onClick(View v) {
  				invBebidas.show(v);
  				invBebidas.setAnimStyle(QuickAction3D.ANIM_REFLECT);
  			}
  		}); 
  	
		Bundle params= getIntent().getExtras();
  		String mascota= params.getString("p");
  		pers=mascota ;
  		ponerPers(mascota);
  	}
	
	public void ponerPers(String mascota){
		if(mascota.equals("chavez")){
  			ImageView personaje = (ImageView) findViewById(R.id.ich);
  	    	personaje.setVisibility(0);
  		}else if(mascota.equals("aristobulo")){
  			ImageView personaje = (ImageView) findViewById(R.id.iar);
  	    	personaje.setVisibility(0);
  		}else if(mascota.equals("iris")){
  			ImageView personaje = (ImageView) findViewById(R.id.iir);
  	    	personaje.setVisibility(0);
  		}else if(mascota.equals("barreto")){
  			ImageView personaje = (ImageView) findViewById(R.id.iba);
  	    	personaje.setVisibility(0);
  		}else if(mascota.equals("capoldo")){
  			ImageView personaje = (ImageView) findViewById(R.id.ica);
  	    	personaje.setVisibility(0);
  		}else if(mascota.equals("maria")){
  			ImageView personaje = (ImageView) findViewById(R.id.ima);
  	    	personaje.setVisibility(0);
  		}else if(mascota.equals("pablo")){
  			ImageView personaje = (ImageView) findViewById(R.id.ipa);
  	    	personaje.setVisibility(0);
  		}else if(mascota.equals("ledezma")){
  			ImageView personaje = (ImageView) findViewById(R.id.ian);
  	    	personaje.setVisibility(0);
  		}
	}
	public void cargarBarra(){
    	HorizontalScrollView barraAct = (HorizontalScrollView) findViewById(R.id.menuInicialBarra);
   	    barraAct.setVisibility(0);
    }
	
	public void quitarBarra(){
    	HorizontalScrollView barraAct = (HorizontalScrollView) findViewById(R.id.menuInicialBarra);
   	    barraAct.setVisibility(4);
    }
	
    public void backToMain1(View view){
    	setContentView(R.layout.main1);
    	finish();
    }
    
    
    public void backToMenu(View view){
    	setContentView(R.layout.menu);
    }
    
    public void backToMenuFromTienda(View view){
    	setContentView(R.layout.menu);
    	ponerPers(pers);
    	
    	this.cargarBarra();
  		this.dinero=(TextView) findViewById(R.id.textDinero);
  		this.vida= (TextView) findViewById(R.id.textVida);
  		this.aprobacion=(TextView) findViewById(R.id.textAprob);
  		this.feliz=(ImageView) findViewById(R.id.feliz);
  		this.hambre=(ProgressBar)findViewById(R.id.barraHambre);
  		this.bano=(ProgressBar)findViewById(R.id.barraBano);
  		
        mHandler = new Handler();
        mHandler.post(mUpdateVida);
        mHandler.post(mUpdateAprobacion);
        mHandler.post(mUpdateFeliz);
        mHandler.post(mUpdateHambre);
        mHandler.post(mUpdateBano);
        dinero.setText(""+d);
  		//Cambiamos la barra que se mostrara en el menu
        
        TextView txtV = (TextView) findViewById(R.id.textVida);  
        TextView txtA = (TextView) findViewById(R.id.textAprob);
        TextView txtD = (TextView) findViewById(R.id.textDinero);
        Typeface font = Typeface.createFromAsset(getAssets(), "sketchblock.ttf");  
        txtV.setTypeface(font);
        txtA.setTypeface(font);
        txtD.setTypeface(font);

  		ActionItem hamburguesaItem 	= new ActionItem(ID_HAMBURGUESA, "Hamburguesa", getResources().getDrawable(R.drawable.hamburg));
  		ActionItem pepsiItem 	= new ActionItem(ID_REFRE, "Pepsi", getResources().getDrawable(R.drawable.refresco));
         ActionItem birraItem 	= new ActionItem(ID_BIRRA, "Birra", getResources().getDrawable(R.drawable.birra));
       ActionItem arepaItem = new ActionItem(ID_AREPA, "Arepa", getResources().getDrawable(R.drawable.miniarepa));
          //use setSticky(true) to disable QuickAction dialog being dismissed after an item is clicked
  		hamburguesaItem.setSticky(true);
        pepsiItem.setSticky(true);
  		birraItem.setSticky(true);
  		//create QuickAction. Use QuickAction.VERTICAL or QuickAction.HORIZONTAL param to define layout 
          //orientation
  		final QuickAction3D invComidas = new QuickAction3D(this, QuickAction3D.HORIZONTAL);
  		final QuickAction3D invBebidas = new QuickAction3D(this, QuickAction3D.HORIZONTAL);
  		//add action items into QuickAction
          invComidas.addActionItem(hamburguesaItem);
          invBebidas.addActionItem(pepsiItem);
          invBebidas.addActionItem(birraItem);
          invComidas.addActionItem(arepaItem);
          
          //Set listener for action item clicked
  		invComidas.setOnActionItemClickListener(new QuickAction3D.OnActionItemClickListener() {			
  			@Override
  			public void onItemClick(QuickAction3D source, int pos, int actionId) {				
  				ActionItem actionItem = invComidas.getActionItem(pos);
  				//here we can filter which action item was clicked with pos or actionId parameter
  				if (actionId == ID_HAMBURGUESA) {
  					
  					if (cantHam > 0){
	  					//Toast.makeText(getApplicationContext(), "Gordeando en calle del hambre no perrito", Toast.LENGTH_SHORT).show();
	  					//vida
	  					v=v+10;
	  					if(v>100){
	  						v=100;
	  					}
	  					vida.setText(""+v);
	  					
	  					//comida
	  					h=h+15;
	  					
	  					if(h>100){
	  						h=100;
	  					}
	  					b=b+12;
	  					if(b>100){
	  						b=100;
	  					}
	  					hambre.setProgress(h);
	  					bano.setProgress(b);
  					}else{
  						Toast.makeText(getApplicationContext(), "No tienes de esta comida debes comprar", Toast.LENGTH_SHORT).show();
  					}
  					
  				} else if(actionId == ID_AREPA){
  					
  					//Toast.makeText(getApplicationContext(), "Una arepita pa' pasa la pea", Toast.LENGTH_SHORT).show();
  					//vida
  					v=v+15;
  					if(v>100){
  						v=100;
  					}
  					vida.setText(""+v);
  					
  					//comida
  					h=h+10;
  					
  					if(h>100){
  						h=100;
  					}
  					b=b+8;
  					if(b>100){
  						b=100;
  					}
  					hambre.setProgress(h);
  					bano.setProgress(b);
  				}	else {
  				
  					Toast.makeText(getApplicationContext(), actionItem.getTitle() + " selected", Toast.LENGTH_SHORT).show();
  				}
  			}
  		});
  		
  		
  		invBebidas.setOnActionItemClickListener(new QuickAction3D.OnActionItemClickListener() {			
  			@Override
  			public void onItemClick(QuickAction3D source, int pos, int actionId) {				
  				ActionItem actionItem = invBebidas.getActionItem(pos);
  				//here we can filter which action item was clicked with pos or actionId parameter
  				if (actionId == ID_REFRE) {
  					//Toast.makeText(getApplicationContext(), "Te toco la sin gas pelaste ", Toast.LENGTH_SHORT).show();
  				//comida
  					h=h+3;
  					
  					if(h>100){
  						h=100;
  					}
  					b=b+10;
  					if(b>100){
  						b=100;
  					}
  					hambre.setProgress(h);
  					bano.setProgress(b);

  					
  					hambre.setProgress(h);
  				} else if (actionId == ID_BIRRA) {
  					if(cantBirra>0){
	  					//Toast.makeText(getApplicationContext(), "Una birra y me voy ..(aja..) ", Toast.LENGTH_SHORT).show();
	  				//vida
	  					v=v-5;
	  					if(v<=0){
	  						v=0;
	  						vida.setText(""+v);
	  						AlertDialog.Builder builder = new AlertDialog.Builder(Mascota.this);
	  	    	    	   builder.setMessage("Perdiste, tu mascota ha muerto")
	  	    	    	          .setCancelable(false)
	  	    	    	          .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
	  	    	    	              public void onClick(DialogInterface dialog, int id) {
	  	    	    	                   Mascota.this.finish();
	  	    	    	              }
	  	    	    	          });
	  	    	    	   AlertDialog alert = builder.create();
	  	    	    	   alert.show();
	  						
	  					}
	  					b=b+15;
	  					if(b>100){
	  						b=100;
	  					}
	  					vida.setText(""+v);
	  					bano.setProgress(b);
	  					
  					}else{
  						Toast.makeText(getApplicationContext(), "No tienes de esta bebida debes comprar", Toast.LENGTH_SHORT).show();
  					}
  				} else {
  					Toast.makeText(getApplicationContext(), actionItem.getTitle() + " selected", Toast.LENGTH_SHORT).show();
  				}
  			}
  		});
  		
  		//set listnener for on dismiss event, this listener will be called only if QuickAction dialog was dismissed
  		//by clicking the area outside the dialog.
  		invComidas.setOnDismissListener(new QuickAction3D.OnDismissListener() {			
  			@Override
  			public void onDismiss() {
  				Toast.makeText(getApplicationContext(), "Dismissed", Toast.LENGTH_SHORT).show();
  			}
  		});
  		
  		//show on btn1
  		Button comer = (Button) this.findViewById(R.id.comer);
  		comer.setOnClickListener(new View.OnClickListener() {
  			@Override
  			public void onClick(View v) {
  				invComidas.show(v);
  				invComidas.setAnimStyle(QuickAction3D.ANIM_REFLECT);
  			}
  		});
       
  		/*Button button1 = (Button) this.findViewById(R.id.button1);
  		button1.setOnClickListener(new OnClickListener() {
  			@Override
  			public void onClick(View v) {
  				quickAction.show(v);
  			}    	 
  		});
  		*/
  		Button beber = (Button) this.findViewById(R.id.beber);
  		beber.setOnClickListener(new OnClickListener() {
  			@Override
  			public void onClick(View v) {
  				invBebidas.show(v);
  				invBebidas.setAnimStyle(QuickAction3D.ANIM_REFLECT);
  			}
  		}); 
  	
  	}
  
    
    
    public void toFunciones(View view){
    	this.quitarBarra();
    	HorizontalScrollView barraAct = (HorizontalScrollView) findViewById(R.id.funcBasicasBarra);
        barraAct.setVisibility(0);
    }
    
    public void toBarraInicialFuncBas(View view){
    	HorizontalScrollView barraAct = (HorizontalScrollView) findViewById(R.id.funcBasicasBarra);
        barraAct.setVisibility(4);
        this.cargarBarra();
    	
    }
    
    public void toBarraInicialAct(View view){
    	HorizontalScrollView barraAct = (HorizontalScrollView) findViewById(R.id.actividadesBarra);
        barraAct.setVisibility(4);
        this.cargarBarra();
    	
    }
    
    public void toActividades(View view){
    	this.quitarBarra();
        HorizontalScrollView barraAct = (HorizontalScrollView) findViewById(R.id.actividadesBarra);
        barraAct.setVisibility(0);
    }
    
    public void toBarraActividadesMini(View view){
    	HorizontalScrollView barraAct = (HorizontalScrollView) findViewById(R.id.actividadesBarra);
        barraAct.setVisibility(0);
        HorizontalScrollView barraAct2 = (HorizontalScrollView) findViewById(R.id.miniJuegosBarra);
        barraAct2.setVisibility(4);
    	
    }
    public void toMinijuegos(View view){
    	HorizontalScrollView barraAct1 = (HorizontalScrollView) findViewById(R.id.actividadesBarra);
        barraAct1.setVisibility(4);
        HorizontalScrollView barraAct = (HorizontalScrollView) findViewById(R.id.miniJuegosBarra);
        barraAct.setVisibility(0);
    }
    
    public void toBarraActividadesTrab(View view){
    	HorizontalScrollView barraAct = (HorizontalScrollView) findViewById(R.id.actividadesBarra);
        barraAct.setVisibility(0);
        HorizontalScrollView barraAct2 = (HorizontalScrollView) findViewById(R.id.trabajarBarra);
        barraAct2.setVisibility(4);
    	
    }
    public void toTrabajar(View view){
    	HorizontalScrollView barraAct1 = (HorizontalScrollView) findViewById(R.id.actividadesBarra);
        barraAct1.setVisibility(4);
        HorizontalScrollView barraAct = (HorizontalScrollView) findViewById(R.id.trabajarBarra);
        barraAct.setVisibility(0);
    }
    
    public void toRobar(View view){
    	setContentView(R.layout.robar);
    }
    
    public void toTienda(View view){
    	setContentView(R.layout.tienda);
    }
    
    public void toTiendaBebidas(View view){
    	setContentView(R.layout.tienda_bebidas);
    }
    
    public void cham(View view){
    	if(cantHam ==0){
    		if (d-5000<0){
    		  AlertDialog.Builder builder = new AlertDialog.Builder(Mascota.this);
  	    	   builder.setMessage("No tienes suficiente dinero para comprar esto necesitas 5000$")
  	    	          .setCancelable(false)
  	    	          .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
  	    	              public void onClick(DialogInterface dialog, int id) {
  	    	                   
  	    	              }
  	    	          });
  	    	   AlertDialog alert = builder.create();
  	    	   alert.show();
    		}else{
       		  d=d-5000;
        		dinero.setText(""+d);
    		  cantHam=1;
    		  AlertDialog.Builder builder = new AlertDialog.Builder(Mascota.this);
 	    	   builder.setMessage("Ya tu mascota puede comer Hamburguesas")
 	    	          .setCancelable(false)
 	    	          .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
 	    	              public void onClick(DialogInterface dialog, int id) {
 	    	                   
 	    	              }
 	    	          });
 	    	   AlertDialog alert = builder.create();
 	    	   alert.show();
    		} 

    	}
    }
    
    public void cbirra(View view){
    	if(cantBirra ==0){
    		if (d-6000<0){
    		  AlertDialog.Builder builder = new AlertDialog.Builder(Mascota.this);
  	    	   builder.setMessage("No tienes suficiente dinero para comprar esto necesitas 6000 $")
  	    	          .setCancelable(false)
  	    	          .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
  	    	              public void onClick(DialogInterface dialog, int id) {
  	    	                   
  	    	              }
  	    	          });
  	    	   AlertDialog alert = builder.create();
  	    	   alert.show();
    		}else{
      		  d=d-6000;
        	  dinero.setText(""+d);
    		  cantBirra=1;
    		  AlertDialog.Builder builder = new AlertDialog.Builder(Mascota.this);
 	    	   builder.setMessage("Ya tu mascota puede beber birras")
 	    	          .setCancelable(false)
 	    	          .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
 	    	              public void onClick(DialogInterface dialog, int id) {
 	    	                   
 	    	              }
 	    	          });
 	    	   AlertDialog alert = builder.create();
 	    	   alert.show();
    		} 

    	}
    }
    public void robaste(View view){
    	if (a-10<0){
    		  AlertDialog.Builder builder = new AlertDialog.Builder(Mascota.this);
  	    	   builder.setMessage("Ya el pueblo esta harto de que robes!! No mas robos!")
  	    	          .setCancelable(false)
  	    	          .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
  	    	              public void onClick(DialogInterface dialog, int id) {
  	    	                   
  	    	              }
  	    	          });
  	    	   AlertDialog alert = builder.create();
  	    	   alert.show();
    	}else{
    		this.a= this.a - 10;
    		this.d= this.d + 1000;
    		aprobacion.setText(""+a);
    		dinero.setText(""+d);
    	}
    }
    
    public void irAlBano(View view){
    	if(b<=30){
    		b=0;
    	}else{
    		b=b-30;
    	}
    }
    
    public void trabajar(View view){
    	if (d-750<0){
  		  AlertDialog.Builder builder = new AlertDialog.Builder(Mascota.this);
	    	   builder.setMessage("No tienes suficiente dinero para hacer viviendas necesitas 750$")
	    	          .setCancelable(false)
	    	          .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
	    	              public void onClick(DialogInterface dialog, int id) {
	    	                   
	    	              }
	    	          });
	    	   AlertDialog alert = builder.create();
	    	   alert.show();
  		}else{
  			if(a>=80){
  				this.a=100;
  			}else{
  				this.a= this.a + 20;
  			}
  			
  			h=h-10;
  			if(h<=0){
  				h=0;
  			}
  			hambre.setProgress(h);
  	    	aprobacion.setText(""+a);
  	    	this.d= this.d - 750;
  	    	dinero.setText(""+d);
  		}

    }
    
    public void paja(View view){
    	if (a-5<0){
  		  AlertDialog.Builder builder = new AlertDialog.Builder(Mascota.this);
	    	   builder.setMessage("Ya el pueblo se canso de tu habladera de paja!! Anda a trabajar!")
	    	          .setCancelable(false)
	    	          .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
	    	              public void onClick(DialogInterface dialog, int id) {
	    	                   
	    	              }
	    	          });
	    	   AlertDialog alert = builder.create();
	    	   alert.show();
    	}else{
    		this.a= this.a - 5;
    		this.f= this.f + 10;
    		aprobacion.setText(""+a);
    	}
    		
    }
    
    public void banarse(View view){
    	this.f=this.f + 5;
    	this.v=this.v +2;
    	if(this.f>=100){
    		this.f=100;
    	}
    	if(this.v>=100){
    		this.v=100;
    	}
    	vida.setText(""+v);
    }
    
    public void dormir(View view){
    	this.v = this.v +5;
    	this.f=this.f +5;
    	if(this.v>=100){
    		this.v=100;
    	}
    	if(this.f>=100){
    		this.f=100;
    	}
    	vida.setText(""+v);
    }
    
  
    
    private Runnable mUpdateVida = new Runnable() {
    	   public void run() {
    		   int tiempo=5000;
    		   vida.setText(""+v);
    		   if(h<=15 || a<=20 || f<=15 ){
    			   v=v-10;
    			   tiempo=2000;
    		   }else{
    			   tiempo=5000;
    			   v--;
    		   }
    		   if(v<=0){
    			   
    			   v=0;
    		   }else if(v>100){
    			   v=100;
    		   }
    	       mHandler.postDelayed(this, tiempo);
    	       if(v==0){
    	    	   vida.setText(""+v);
    	    	   AlertDialog.Builder builder = new AlertDialog.Builder(Mascota.this);
    	    	   builder.setMessage("Perdiste, tu mascota ha muerto")
    	    	          .setCancelable(false)
    	    	          .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
    	    	              public void onClick(DialogInterface dialog, int id) {
    	    	                   Mascota.this.finish();
    	    	              }
    	    	          });
    	    	   AlertDialog alert = builder.create();
    	    	   alert.show();
    	    	   tiempo=1000000;
    	       }
    	    }
   };
   
   private Runnable mUpdateAprobacion = new Runnable() {
	   public void run() {
		   if(a<=0){
			   a=0;
		   }else if(a>100){
			   a=100;
		   }
	       aprobacion.setText(""+a);
	       a--;
	       mHandler.postDelayed(this, 7000);

	    }
};  
private Runnable mUpdateFeliz = new Runnable() {
	   public void run() {
		   if(f<=0){
			   f=0;
		   }else if(f>100){
			   f=100;
		   }
		   if(f<=25){
	    	   feliz.setImageDrawable(getResources().getDrawable(R.drawable.triste));
	       }else if(f>25 && f<=75){
	    	   feliz.setImageDrawable(getResources().getDrawable(R.drawable.normal));
	       }else if(f>75){
	    	   feliz.setImageDrawable(getResources().getDrawable(R.drawable.feliz));
	       }
	       f--;
	       mHandler.postDelayed(this, 3500);
	       

	    }
};

private Runnable mUpdateHambre = new Runnable() {
	   public void run() {
		   if(h<=0){
			   h=0;
		   }else if(h>100){
			   h=100;
		   }
		   hambre.setProgress(h);
	       
	       h--;
	       mHandler.postDelayed(this, 2000);
	       

	    }
};
private Runnable mUpdateBano = new Runnable() {
	   public void run() {
		   if(b<=0){
			   b=0;
		   }else if(b>100){
			   b=100;
		   }
		   bano.setProgress(b);
	       
	       b++;
	       mHandler.postDelayed(this, 7800);
	       

	    }
};
    
}
